/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - resource
// Copyright( c) 2014.  All Rights Reserved
//
// File:		AETexture.cpp
// Author:		Gianluca Belardelli
// Date:		02/10/2014
//
/////////////////////////////////////////////////////////////////////////
#include <AEEngine.h>

//////////////////////////////////////////////////
// Static methods
//////////////////////////////////////////////////
AEBOOL32 AETexture::ConvertTextureFilename( char *lpDest, const char *lpSrc )
{
	return 0;
}

AETextureFormat AETexture::GetCompatibleDepthTextureFormat( const AEVideoConfig &vcVideoConfig )
{
	return A4B4G4R4;
}

AEUINT32 AETexture::GetBitsPerPixel( AETextureFormat eFormat )
{
	return 0;
}

AEBOOL32 AETexture::IsDepthStencilFormat( AETextureFormat eFormat )
{
	return 0;
}

AEBOOL32 AETexture::IsFormatCompressed( AETextureFormat eFormat )
{
	return 0;
}

AEINT32 AETexture::CountMipLevels( AEINT32 nWidth, AEINT32 nHeight )
{
	return 0;
}

AEINT32 AETexture::CountMipLevelsTill4x4( AEINT32 nWidth, AEINT32 nHeight )
{
	return 0;
}

AEINT32 AETexture::GetColorDepthFromTextureFormat( AETextureFormat eFormat )
{
	return 0;
}

#if defined(AE_OPENGL)
AEBOOL32 AETexture::ToGLESTextureFormatAndType( AETextureFormat eFormat,
									AEINT32 &nFormatOut,
									AEINT32 &nType,
									AEBOOL32 &bIsCompressedFormat )
{
	return 0;
}

AEBOOL32 AETexture::ToGLESRenderTargetFormatAndType( AETextureFormat eFormat,
									AEINT32 &nFormatOut,
									AEINT32 &nRenderBufferFormat,
									AEINT32 &nType,
									AEBOOL32 &bIsCompressedFormat )
{
	return 0;
}

AEBOOL32 AETexture::ToGLESDepthStencilFormatAndType( AETextureFormat eFormat,
									AEINT32 &nFormatOut,
									AEINT32 &nRenderBufferFormat,
									AEINT32 &nType,
									AEBOOL32 &bIsCompressedFormat )
{
	return 0;
}

const char *AETexture::GetGLES2TextureExtensionString( AETextureFormat eFormat )
{
	return 0L;
}

const char *AETexture::GetGLES2DepthStencilExtensionString( AETextureFormat eFormat )
{
	return 0L;
}

/*
AEBOOL32 AETexture::GetPlatformSpecificTextureFileName( const char* lpOriginalFilename,
									char* lpOutFilename,
									IVFileStreamManager *lpFileManager,
									AEBOOL32 &bIsNativeFormat )
{
	return 0;
}
*/
#endif

AEINT32 AETexture::GetBlockSizeInTexels( AETextureFormat eFormat )
{
	return 0;
}

AEINT32 AETexture::GetBlockSizeInBytes( AETextureFormat eFormat )
{
	return 0;
}

//////////////////////////////////////////////////
// Public class methods
//////////////////////////////////////////////////
AETexture::AETexture( AEResourceManager *lpParentManager ) : AEResource( lpParentManager )
{
	m_bDestroyHandleOnLostDevice = 0;
	m_bIsVertexTexture = 0;
	m_bIsCreatedFromMemory = 0;

	m_uiLoadingFlags = 0;
	m_sDepth = 0;
	m_cMipLevels = 0;
	m_cTextureType = AETT_TEXTURE2D;
	m_cTextureFormat = UNKNOWN;
	m_bIsUpsideDown = 0;
}

AETexture::~AETexture( void )
{
}

void AETexture::AdjustDownScaleFactor( void )
{
}

AEBOOL32 AETexture::IsRenderable( void ) const
{
	return 0;
}

void AETexture::GetTextureDimensions( AEINT32 &nSizeX, AEINT32 &nSizeY, AEINT32 &nDepth ) const
{
	nSizeX = m_sSizeX;
	nSizeY = m_sSizeY;
	nDepth = m_sDepth;
}

void AETexture::GetRealTextureDimensions( AEINT32 &nSizeX, AEINT32 &nSizeY, AEINT32 &nDepth ) const
{
}

AEBOOL32 AETexture::HasAlphaChannel( void ) const
{
	return 0;
}

AEINT32 AETexture::GetMipLevelSize( AEINT32 nMipLevel )
{
	return 0;
}

AEINT32 AETexture::GetMipLevelOffset( AEINT32 nMipLevel )
{
	return 0;
}


AEBOOL32 AETexture::HasDeviceHandle( void )
{
	return 0;
}

void AETexture::ReleaseDeviceHandle( void )
{
}

AEBOOL32 AETexture::UpdateRect( AEINT32 nMipLevel,
		AEINT32 nX1, AEINT32 nY1,
		AEINT32 nWidth, AEINT32 nHeight,
		AEINT32 nSrcStride, const void *lpData,
		AEINT32 nLockFlags, AEINT32 nFaceOrSlice )
{
	return 0;
}

void AETexture::SetSRGB( AEBOOL32 bNewStatus )
{
}
/*
void AETexture::GetDependencies( AEResourceSnapshot &rsSnapshot )
{
}
*/
AEBOOL32 AETexture::GetReplacementTexture( char *lpFileName, AEBOOL32 &bIsNativeFormat )
{
	return 0;
}

AEBOOL32 AETexture::LoadCustomTexture( const char *lpFileName )
{
	return 0;
}

void AETexture::CreateMipmaps( void )
{
}

void AETexture::SetAnimationInfo( AETextureAnimInfo *lpInfo )
{
}

//////////////////////////////////////////////////
// Protected class methods
//////////////////////////////////////////////////
AEBOOL32 AETexture::Load( const char *lpFileName )
{
	//AEASSERT_MSG( lpFileName != 0L, "Impossibile caricare una texture con un nome file nullo." );
	AETextureManager *lpMgr = (AETextureManager *)m_lpParentManager;
	AEResource *lpResource = lpMgr->GetResourceByName( lpFileName );

	if( lpResource )
		return AETRUE;

	SetFilename( lpFileName );
	return Reload();

	/*AETextureManager *lpMgr = (AETextureManager *)m_lpParentManager;

	const char *lpExt = AEStringUtils::GetExtension( lpFileName );
	if( lpExt == 0L )
		return 0;

	AETextureLoaderI *lpLoader = lpMgr->GetLoaderForExtension( lpExt );
	if( !lpLoader )
		return 0;

	AEINT32 uiLoadingFlags = 0;
	if( lpLoader->CreateTexture( lpFileName, uiLoadingFlags ) )
	{
		m_sSizeX = lpLoader->GetWidth();
		m_sSizeY = lpLoader->GetHeight();

		if( m_sSizeY < 0 )
		{
			m_sSizeY *= -1;
			m_bIsUpsideDown = 1;
		}

		m_cTextureFormat = lpLoader->GetTextureFormat();

		CreateDeviceHandle( lpLoader->GetRawBuffer(0) );
	}


	return 0;*/
}

AEBOOL32 AETexture::Reload( void )
{
	AEASSERT_MSG( GetFilename() != AENULL, "Oggetto non completamente inizializzato." );
	AETextureManager *lpMgr = (AETextureManager *)m_lpParentManager;

	const char *lpExt = AEStringUtils::GetExtension( GetFilename() );
	if( lpExt == AENULL )
		return AEFALSE;

	AETextureLoaderI *lpLoader = lpMgr->GetLoaderForExtension( lpExt );
	if( !lpLoader )
		return AEFALSE;

	AEINT32 uiLoadingFlags = 0;
	if( lpLoader->CreateTexture( GetFilename(), uiLoadingFlags ) )
	{
		m_sSizeX = lpLoader->GetWidth();
		m_sSizeY = lpLoader->GetHeight();

		if( m_sSizeY < 0 )
		{
			m_sSizeY *= -1;
			m_bIsUpsideDown = 1;
		}

		m_cTextureFormat = lpLoader->GetTextureFormat();

		CreateDeviceHandle( lpLoader->GetRawBuffer(0) );
		return AETRUE;
	}

	return AEFALSE;
}

AEBOOL32 AETexture::Unload( void )
{
	return 0;
}

void AETexture::AdjustFlagsFromMetadata( const char *lpMetadata, AEUINT32 &nFlags )
{
}

void AETexture::EnableDestroyHandleOnLostDevice( void )
{
}

void AETexture::Clear( void )
{
}

void AETexture::AccumulateMemoryFootprint( AEUINT32 &uiUniqueSys, AEUINT32 &uiUniqueGPU,
							AEUINT32 &uiDependentSys, AEUINT32 &uiDependentGPU )
{
}
/*
void AETexture::CreateFromReplacementBlock( AEResourceSnapshotEntry &rsEntry )
{
}
*/
AEINT32 AETexture::ComputeDownScaleFactor( void )
{
	return 0;
}

void AETexture::SetPathname( const char *lpName, AEBOOL32 bConvert )
{
}
/*
void AETexture::Init( const AETextureLoader &tlLoader )
{
}
*/
